<template src="./index.html"></template>

<script>
import MedicalRecordOperationHistoryService from "../../../../../../_services/medicalRecordOperationHistory.service";
export default {
  name: "TianDingPatientMePastHistoryModifyComponent",
  data() {
    return {
      params: {
        HistoryID: "0", //手术既往史编号
        Operation: "0", //手术选择 = ['0', '1', '2']
        OperationDate: "", //手术日期
        OperationHospital: "", //手术医院
        OperationRemark: "", //手术描述
        Remark: "", //其他描述
        UserID: "0" //
      },
      showOperationDate: false
    };
  },
  mounted() {
    let pastHistory = JSON.parse(this.local$.getItem("tdPastHistory"));
    if (pastHistory !== null) {
      this.params = pastHistory;
      this.params.Operation = this.params.Operation.toString();
      this.utils$.dataFormat(this.params);
    }
  },
  methods: {
    getOperationDate(event) {
      this.params.OperationDate = event;
    },
    btnSubmit() {
      if (!this.params.OperationDate) {
        this.toast$("请填写手术年月");
        return;
      }

      if (!this.params.OperationHospital) {
        this.toast$("请填写手术医院");
        return;
      }

      if (this.params.Operation === "2") {
        if (!this.params.OperationRemark) {
          this.toast$("请填写其他描述");
          return;
        }
      }

      if (!this.params.Remark) {
        this.toast$("请填写手术描述");
        return;
      }

      let user = JSON.parse(this.local$.getItem("tdUser"));

      let params = {
        HistoryID: parseInt(this.params.HistoryID), //手术既往史编号
        Operation: parseInt(this.params.Operation), //手术选择 = ['0', '1', '2']
        OperationDate: this.params.OperationDate, //手术日期
        OperationHospital: this.params.OperationHospital, //手术医院
        OperationRemark: this.params.OperationRemark
          ? this.params.OperationRemark
          : "无", //手术描述
        Remark: this.params.Remark ? this.params.Remark : "无", //其他描述
        UserID: user.UserID //
      };

      if (params.HistoryID > 0) {
        MedicalRecordOperationHistoryService.updateOperationHistory(
          params
        ).then(response => {
          if (response && response.Data > 0) {
            this.toast$("保存成功！");
          } else {
            this.toast$("保存失败！");
          }
          this.$router.push({ name: "tdPatientMeMedicalPastHistory" });
        });
      } else {
        MedicalRecordOperationHistoryService.addOperationHistory(params).then(
          response => {
            if (response && response.Data > 0) {
              this.toast$("保存成功！");
            } else {
              this.toast$("保存失败！");
            }
            this.$router.push({ name: "tdPatientMeMedicalPastHistory" });
          }
        );
      }
    }
  }
};
</script>
